#include <iostream>
#include <string>
#include <memory>

class Computer
{
public:
    Computer()//为什么不写这个构造函数
    {}
    void setboard(const std::string& board)
    {
        _board = board;
    }
    void setdisplay(const std::string& display)
    {
        _display = display;
    }
    virtual void setOs() = 0;
    void showparameter()
    {
        std::string parameter = "Computer parameter:\n";
        parameter += "\tBoard: " + _board + "\n";
        parameter += "\tDisplay: " + _display + "\n";
        parameter += "\tOs: " + _Os + "\n";
        std::cout << parameter << std::endl;
    }
protected:
    std::string _board;
    std::string _display;
    std::string _Os;
};
class MacComputer : public Computer
{
public:
    void setOs() override
    {
        _Os = "Max Os x64";
    }
};
class Builder
{
public:
    virtual void buildboard(const std::string& board) = 0;
    virtual void builddisplay(const std::string& display) = 0;
    virtual void buildOs() = 0;
    virtual std::shared_ptr<Computer> build() = 0;

};
class MacBuilder : public Builder
{
public:
    MacBuilder():_computer(new MacComputer())
    {}
    void buildboard(const std::string& board) override
    {
        _computer->setboard(board);
    }
    void builddisplay(const std::string& display) override
    {
        _computer->setdisplay(display);
    }
    void buildOs() override//为什么这里不给参数 
    {
        _computer->setOs();
    }
    std::shared_ptr<Computer> build() override
    {
        return _computer;
    }
private:
    std::shared_ptr<Computer> _computer;//**//
};
class Director
{
public:
    // Director():_builder(new MacBuilder())
    Director(Builder* build):_builder(build)
    {}
    std::shared_ptr<Computer> construct(const std::string& board, const std::string& display)
    {
        _builder->buildboard(board);
        _builder->builddisplay(display);
        _builder->buildOs();
        return _builder->build();
    }   
private:
    std::shared_ptr<Builder> _builder;
};
int main()
{
    // Director dir;
    // std::shared_ptr<Computer> computer = dir.construct("荣耀主板", "华为显示器");
    // computer->showparameter();
    Builder* builder = new MacBuilder();
    std::unique_ptr<Director> director(new Director(builder));
    std::shared_ptr<Computer> computer = director->construct("英伟达主板", "英特尔显示器");
    computer->showparameter();
    return 0;
}
